/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Room;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import things.World;

/**
 *
 * @author Ben
 */
public final class Room {

    public int xLoc;
    public int yLoc;
    public boolean isGold = false;
    public boolean isPit = false;
    public boolean hasBreeze = false;
    public World w;
    public boolean hasWumpus;

    public Room(World w, int x, int y, Color c) {
        this.w = w;
        xLoc = x;
        yLoc = y;
        drawRoom(x, y, c);
    }

    public Room(World w, int x, int y) {
        this.w = w;
        xLoc = x;
        yLoc = y;
        drawRoom(x, y, w.getBackground());
    }

    /**
     * Draws a room at the cell x,y. Top left is [0,0]
     * @param x X parameter of the pit
     * @param y Y parameter of the pit
     * @param g2 Graphics object to draw on
     * @param c Color to make the pit
     */
    public void drawRoom(int x, int y, Color c) {
        Graphics2D g2 = w.g2;
        if (x <= 3 || x >= 0 || y <= 3 || y >= 0) {
            Dimension cellSize = new Dimension(w.cellSize.width, w.cellSize.height);
            Dimension cellLocation = new Dimension(cellSize.width * x, cellSize.height * y);
            g2.setColor(c);
            int upperLeftX = cellLocation.width + 1;
            int upperLeftY = cellLocation.height + 1;
            int cellWidth = cellSize.width - 1;
            int cellHeight = cellSize.height - 1;
            if (x == 0 && y == 0) { // If it's the top left cell, shift up and left 1 pixel, stretch right and down 1 pixel
                upperLeftX -= 1;
                upperLeftY -= 1;
                cellWidth += 1;
                cellHeight += 1;
            }
            if (x == 0 && y != 0) { // If it's on the left, but not top, move left one pixel and wider one pixel
                upperLeftX -= 1;
                cellWidth += 1;
            }
            if (y == 0) { // If it's on the top row, move up one pixel and make one pixel taller
                upperLeftY -= 1;
                cellHeight += 1;
            }
            g2.fillRect(upperLeftX, upperLeftY, cellWidth, cellHeight);
        }
    }

    /**
     * Creates a pit at location [x,y]. Color default is red.
     * Top left cell is [0,0]
     * @param x X location of the pit
     * @param y Y location of the pit
     * @param a If you want where the smells are to be in pink or not.
     */
    public void drawPit(int x, int y, boolean a, Color c) {
        isPit = true;
        if (xLoc > 0) {
            w.rs[xLoc - 1][yLoc].hasBreeze = true;

        }
        if (xLoc < 3) {
            w.rs[xLoc + 1][yLoc].hasBreeze = true;
        }
        if (yLoc > 0) {
            w.rs[xLoc][yLoc - 1].hasBreeze = true;

        }
        if (yLoc < 3) {
            w.rs[xLoc][yLoc + 1].hasBreeze = true;
        }
        drawRoom(xLoc, yLoc, c);
        if (a) {
            drawRoom(xLoc - 1, yLoc, Color.pink);
            drawRoom(xLoc + 1, yLoc, Color.pink);
            drawRoom(xLoc, yLoc + 1, Color.pink);
            drawRoom(xLoc, yLoc - 1, Color.pink);
        }
    }

    /**
     * Makes the current room a pit with default color of red.
     * @param a Do you want the adjacent rooms with breeze colored?
     */
    public void makePit(boolean a) {
        drawPit(xLoc, yLoc, a, Color.red);
    }

    public void makeGold() {
        isGold = true;
        drawRoom(xLoc, yLoc, Color.yellow);
    }

    public void makeWumpus() {
        hasWumpus = true;
        drawRoom(xLoc, yLoc, Color.green);
    }

    public boolean isPit() {
        return isPit;
    }
}
